package com.car.order.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.car.commons.core.model.WoniuException;
import com.car.order.dto.GEO.AddressResult2;
import com.car.order.dto.storesInfo.StoresInfoDto;
import com.car.order.entity.form.storesInfo.StoresInfoFindPageForm;
import com.car.order.entity.form.storesInfo.StoresInfoInsertForm;
import com.car.order.entity.param.storesInfo.StoresInfoFindPageParam;
import com.car.order.mapper.StoresInfoMapper;
import com.car.order.entity.StoresInfo;
import com.car.order.service.StoresInfoService;
import com.car.order.util.GEOUtil;
import org.redisson.api.GeoUnit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.List;

/**
 * @author 杜岷芫
 * @since 2024-09-03 15:16:50
 */
@Service
@Slf4j
public class StoresInfoServiceImpl extends ServiceImpl<StoresInfoMapper, StoresInfo> implements StoresInfoService {

    @Autowired
    private StoresInfoMapper storesInfoMapper;
    @Autowired
    private GEOUtil geoUtil;


    @Override
    public StoresInfo insert(StoresInfoInsertForm form) throws Exception{
        StoresInfo storesInfo = BeanUtil.toBean(form, StoresInfo.class);
        AddressResult2 addressResult2 = geoUtil.addressConvert(storesInfo.getStoresAddress());
        storesInfo.setLatitude(addressResult2.getLat());
        storesInfo.setLongitude(addressResult2.getLng());
        System.out.println(addressResult2);
        return storesInfo;
    }

    @Override
    public Page<StoresInfo> findPage(StoresInfoFindPageForm form) throws Exception{
        AddressResult2 addressResult2 = geoUtil.addressConvert(form.getAddress());
        System.out.println(addressResult2);
        StoresInfoFindPageParam param = BeanUtil.toBean(form, StoresInfoFindPageParam.class);
        param.setLatitude(addressResult2.getLat());
        param.setLongitude(addressResult2.getLng());
        List<StoresInfoDto> storesInfoDtos = storesInfoMapper.findPage(param);
        System.out.println(storesInfoDtos);
        return null;
    }
}